import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/19 15:39
 * @description 排序 + 贪心
 */
public class Solution2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        int[] nums = {1, 1, 2, 2, 3};
        solution2.reductionOperations(nums);
    }
    public int reductionOperations(int[] nums) {
        Arrays.sort(nums);
        // cnt 每个元素的操作次数， ans 总操作次数
        int cnt = 0, ans = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[i - 1]) {
                ++cnt;
            }
            ans += cnt;
        }
        return ans;
    }
}
